package per.zqx.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import lombok.SneakyThrows;
import per.zqx.utils.RabbitUtils;

import java.nio.charset.StandardCharsets;

/**
 * TopicProducer
 *
 * @author Sa  2021-06-02 21:05
 */
public class TopicProducer {
    static final String EXCHANGE_NAME = "topic_exchange_name";
    @SneakyThrows
    public static void main(String[] args) {
        try (Connection connection = RabbitUtils.getConnection()) {
            final Channel channel = connection.createChannel();
            // 类型是 topic
            channel.exchangeDeclare(EXCHANGE_NAME, "topic");
            String key1 = "success.log";
            String msg1 = "success.log";
            channel.basicPublish(EXCHANGE_NAME, key1, null, msg1.getBytes(StandardCharsets.UTF_8));
            String key2 = "error.log";
            String msg2 = "error.log";
            channel.basicPublish(EXCHANGE_NAME, key2, null, msg2.getBytes(StandardCharsets.UTF_8));
            String key3 = "a.b.c.log";
            String msg3 = "a.b.c.log";
            channel.basicPublish(EXCHANGE_NAME, key3, null, msg3.getBytes(StandardCharsets.UTF_8));
        }
    }
}
